define(['jquery'],function($){
		
	return {	
		jiexi : function (dat){
			
			var categories = dat.data.categories;
			var products = dat.data.products;
			var arr = [];
			
			for (var i in categories){
				var name = categories[i].name;
				var li = $('<li></li>').attr('class','categories_li').text(name).appendTo('.categories_ul');	
				var id = categories[i].id;
				arr.push(id);
			}

			for(var num of arr){
				var productsArr = products[num];
				var ul = $('<ul></ul>').attr('class','product_ul').appendTo('#ul_box');
				
				for(var j in productsArr){
					var str1, str2;
					var img = $('<img />').attr('src',productsArr[j].img);
					if(productsArr[j].org_source_value == 1){
						str1 = '<span class="jingXuan">精选</span>';
					} else{
						str1 = '<span></span>';
					}
					if(productsArr[j].pm_desc == ""){
						str2 = '<span></span>';
					}else{
						str2 = '<span class="give">'+productsArr[j].pm_desc+'</span>';	
					}
					
				var li = $('<li></li>').attr('class','product_li').appendTo('.product_ul');
				var div_img = $('<div></div>').attr('class','pic').appendTo(li);
				var div_con = $('<div></div>').attr('class','con').appendTo(li);
				
				div_con.append(`
						<p class="des">${productsArr[j].long_name}</p>
						<b>${str1}</b>
						<b>${str2}</b>
						<p class="weight">${productsArr[j].specifics}</p>
						<p>
							<span class="new_price">¥${productsArr[j].partner_price}</span>
							<span class="old_price">¥${productsArr[j].market_price}</span>
						</p>
						<p class="num_box">
							<span class="diff"></span>
							<span class="number"></span>
							<span class="tianjia"></span>
						</p>
				`);
				div_img.append(img);
				
				}
			}
	//-------------点击切换效果----------------------------
			var lis = document.querySelectorAll('.categories_li');
			var divs = document.querySelectorAll('.product_ul');
			
			for(var i=0;i<lis.length;i++){
				lis[i].index = i;
				lis[i].onclick = function(){
					for(var i=0; i<divs.length; i++){
						lis[i].id = '';
						divs[i].style.display = 'none';
					}
					this.id = 'active';
					divs[this.index].style.display = 'block';
				}
			}
		}
	}
})